package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.entitry.SpecGroup;
import com.leyou.item.mapper.SpecGroupMapper;
import com.leyou.item.service.SpecGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author 张伟奇
 * @Date 2021/7/17 19:23
 * @description
 * @Version 1.0
 **/
@Service
public class SpecGroupServiceImpl extends ServiceImpl<SpecGroupMapper, SpecGroup> implements SpecGroupService {
    @Autowired
    private SpecGroupMapper specGroupMapper;


    @Override
    public List<SpecGroupDTO> listSpecGroupByCategory(Long cid) {
        List<SpecGroup> listSpecByCategory =
                this.specGroupMapper.selectList(new QueryWrapper<SpecGroup>().eq("category_id", cid));
        return  SpecGroupDTO.convertEntityList(listSpecByCategory);
    }

    @Override
    @Transactional
    public void saveGroupSaveGroup(SpecGroupDTO specGroupDTO) {
        this.specGroupMapper.insert(specGroupDTO.toEntity(SpecGroup.class));
    }

    @Override
    @Transactional
    public void updateGroupSaveGroup(SpecGroupDTO specGroupDTO) {
        this.specGroupMapper.updateById(specGroupDTO.toEntity(SpecGroup.class));

    }

    @Override
    public List<SpecGroupDTO> listSpecGroupWithParams(Long id) {

        return this.specGroupMapper.listSpecGroupWithParams(id);
    }

}
